/*
 * SplashScreen.java
 *
 * Created on 22. April 2007, 12:33
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package de.tor.screens;

import com.golden.gamedev.GameEngine;
import com.golden.gamedev.GameObject;
import com.golden.gamedev.object.GameFont;
import com.golden.gamedev.object.Timer;
import de.tor.SpaceTiger;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;

/**
 *
 * @author Charon
 */
public class SplashScreen extends GameObject {
    
    BufferedImage	title;
    BufferedImage	arrow;
    
    GameFont		font;
    boolean			blink;
    int				option;
    Timer			blinkTimer = new Timer(400);
    /** Creates a new instance of SplashScreen */
    public SplashScreen(GameEngine parent) {
        super(parent);
    }
    
    public void initResources() {
        title = getImage("resources/title.jpg", false);
        arrow = getImage("resources/Arrow.png");
        
        font = parent.fontManager.getFont(getImages("resources/font.png", 20, 3),
                " !            .,0123" +
                "456789:   -? ABCDEFG" +
                "HIJKLMNOPQRSTUVWXYZ ");
    }
    
    public void update(long l) {
        if (blinkTimer.action(l)) {
            blink = !blink;
        }
        
        switch (bsInput.getKeyPressed()) {
            case KeyEvent.VK_ENTER :
                if (option == 0) {
                    // start
                    parent.nextGameID = SpaceTiger.GAME_MODE;
                    finish();
                } else if (option == 1) {
                    // load
                    
                } else if (option == 2) {
                    // end
                    finish();
                }
                break;
                
            case KeyEvent.VK_UP :
                option--;
                if (option < 0) option = 2;
                break;
                
            case KeyEvent.VK_DOWN :
                option++;
                if (option > 2) option = 0;
                break;
                
            case KeyEvent.VK_ESCAPE :
                finish();
                break;
        }
    }
    
    public void render(Graphics2D graphics2D) {
        
        graphics2D.drawImage(title, 0, 0,   null);
        font.drawString(graphics2D, "START", 450, 300);
        font.drawString(graphics2D, "LOAD", 450, 320);
        font.drawString(graphics2D, "END", 450, 340);
        
        font.drawString(graphics2D, "PRESS Z FOR ACTION", 10, 455);
        if (!blink) {
            graphics2D.drawImage(arrow, 434, 297+(option*20), null);
        }
        
    }
    
}
